<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class T_kur_skbm_ip extends CI_Controller 
{
	function __construct()
	{
		parent::__construct();

		$this->load->library( 'template' ); 
		$this->load->model( 'model_t_kur_skbm_ip' ); 
		
		$this->load->helper( 'form' );
		$this->load->helper( 'language' ); 
		$this->load->helper( 'url' );
        $this->load->model( 'model_auth' );

        $this->logged_in = $this->model_auth->check( TRUE );
        $this->template->assign( 'logged_in', $this->logged_in );

		$this->lang->load( 'db_fields', 'english' ); // This is the language file
	}



    /**
     *  LISTS MODEL DATA INTO A TABLE
     */         
    function index( $page = 0 )
    {
        $this->model_t_kur_skbm_ip->pagination( TRUE );
		$data_info = $this->model_t_kur_skbm_ip->lister( $page );
        $fields = $this->model_t_kur_skbm_ip->fields( TRUE );
        

        $this->template->assign( 'pager', $this->model_t_kur_skbm_ip->pager );
		$this->template->assign( 't_kur_skbm_ip_fields', $fields );
		$this->template->assign( 't_kur_skbm_ip_data', $data_info );
        $this->template->assign( 'table_name', 'T_kur_skbm_ip' );
        $this->template->assign( 'template', 'list_t_kur_skbm_ip' );
        
		$this->template->display( 'frame_admin.tpl' );
    }



    /**
     *  SHOWS A RECORD VIEW
     */
    function show( $id )
    {
		$data = $this->model_t_kur_skbm_ip->get( $id );
        $fields = $this->model_t_kur_skbm_ip->fields( TRUE );
        

        
        $this->template->assign( 'id', $id );
		$this->template->assign( 't_kur_skbm_ip_fields', $fields );
		$this->template->assign( 't_kur_skbm_ip_data', $data );
		$this->template->assign( 'table_name', 'T_kur_skbm_ip' );
		$this->template->assign( 'template', 'show_t_kur_skbm_ip' );
		$this->template->display( 'frame_admin.tpl' );
    }



    /**
     *  SHOWS A FROM, AND HANDLES SAVING IT
     */         
    function create( $id = false )
    {
		$this->load->library('form_validation');
        
		switch ( $_SERVER ['REQUEST_METHOD'] )
        {
            case 'GET':
                $fields = $this->model_t_kur_skbm_ip->fields();
                
                
                
                $this->template->assign( 'action_mode', 'create' );
        		$this->template->assign( 't_kur_skbm_ip_fields', $fields );
                $this->template->assign( 'metadata', $this->model_t_kur_skbm_ip->metadata() );
        		$this->template->assign( 'table_name', 'T_kur_skbm_ip' );
        		$this->template->assign( 'template', 'form_t_kur_skbm_ip' );
        		$this->template->display( 'frame_admin.tpl' );
            break;

            /**
             *  Insert data TO t_kur_skbm_ip table
             */
            case 'POST':
                $fields = $this->model_t_kur_skbm_ip->fields();

                /* we set the rules */
                /* don't forget to edit these */
				$this->form_validation->set_rules( 'KD_KURIKULUM', lang('KD_KURIKULUM'), 'required|max_length[2]' );
				$this->form_validation->set_rules( 'KD_TINGKAT_KELAS', lang('KD_TINGKAT_KELAS'), 'required|max_length[2]' );
				$this->form_validation->set_rules( 'KD_PROGRAM_PENGAJARAN', lang('KD_PROGRAM_PENGAJARAN'), 'required|max_length[1]' );
				$this->form_validation->set_rules( 'KD_PERIODE_BELAJAR', lang('KD_PERIODE_BELAJAR'), 'required|max_length[1]' );
				$this->form_validation->set_rules( 'KD_MATA_PELAJARAN_DIAJARKAN', lang('KD_MATA_PELAJARAN_DIAJARKAN'), 'required|max_length[5]' );
				$this->form_validation->set_rules( 'ID_STANDAR', lang('ID_STANDAR'), 'required|max_length[3]|integer' );
				$this->form_validation->set_rules( 'ID_KD', lang('ID_KD'), 'required|max_length[3]|integer' );
				$this->form_validation->set_rules( 'ID_IP', lang('ID_IP'), 'required|max_length[3]|integer' );
				$this->form_validation->set_rules( 'SKBM_IP', lang('SKBM_IP'), 'required|max_length[5]|numeric' );
				$this->form_validation->set_rules( 'USERNAME', lang('USERNAME'), 'required|max_length[20]' );
				$this->form_validation->set_rules( 'TANGGAL_AKSES', lang('TANGGAL_AKSES'), 'required' );

				$data_post['KD_KURIKULUM'] = $this->input->post( 'KD_KURIKULUM' );
				$data_post['KD_TINGKAT_KELAS'] = $this->input->post( 'KD_TINGKAT_KELAS' );
				$data_post['KD_PROGRAM_PENGAJARAN'] = $this->input->post( 'KD_PROGRAM_PENGAJARAN' );
				$data_post['KD_PERIODE_BELAJAR'] = $this->input->post( 'KD_PERIODE_BELAJAR' );
				$data_post['KD_MATA_PELAJARAN_DIAJARKAN'] = $this->input->post( 'KD_MATA_PELAJARAN_DIAJARKAN' );
				$data_post['ID_STANDAR'] = $this->input->post( 'ID_STANDAR' );
				$data_post['ID_KD'] = $this->input->post( 'ID_KD' );
				$data_post['ID_IP'] = $this->input->post( 'ID_IP' );
				$data_post['SKBM_IP'] = $this->input->post( 'SKBM_IP' );
				$data_post['USERNAME'] = $this->input->post( 'USERNAME' );
				$data_post['TANGGAL_AKSES'] = $this->input->post( 'TANGGAL_AKSES' );

                if ( $this->form_validation->run() == FALSE )
                {
                    $errors = validation_errors();
                    
                    
                    
                    
              		$this->template->assign( 'errors', $errors );
              		$this->template->assign( 'action_mode', 'create' );
            		$this->template->assign( 't_kur_skbm_ip_data', $data_post );
            		$this->template->assign( 't_kur_skbm_ip_fields', $fields );
                    $this->template->assign( 'metadata', $this->model_t_kur_skbm_ip->metadata() );
            		$this->template->assign( 'table_name', 'T_kur_skbm_ip' );
            		$this->template->assign( 'template', 'form_t_kur_skbm_ip' );
            		$this->template->display( 'frame_admin.tpl' );
                }
                elseif ( $this->form_validation->run() == TRUE )
                {
                    $insert_id = $this->model_t_kur_skbm_ip->insert( $data_post );
                    
					redirect( 't_kur_skbm_ip' );
                }
            break;
        }
    }



    /**
     *  DISPLAYS THE POPULATED FORM OF THE RECORD
     *  This method uses the same template as the create method
     */
    function edit( $id = false )
    {
        $this->load->library('form_validation');

        switch ( $_SERVER ['REQUEST_METHOD'] )
        {
            case 'GET':
                $this->model_t_kur_skbm_ip->raw_data = TRUE;
        		$data = $this->model_t_kur_skbm_ip->get( $id );
                $fields = $this->model_t_kur_skbm_ip->fields();
                
                
                
                
          		$this->template->assign( 'action_mode', 'edit' );
        		$this->template->assign( 't_kur_skbm_ip_data', $data );
        		$this->template->assign( 't_kur_skbm_ip_fields', $fields );
                $this->template->assign( 'metadata', $this->model_t_kur_skbm_ip->metadata() );
        		$this->template->assign( 'table_name', 'T_kur_skbm_ip' );
        		$this->template->assign( 'template', 'form_t_kur_skbm_ip' );
        		$this->template->assign( 'record_id', $id );
        		$this->template->display( 'frame_admin.tpl' );
            break;
    
            case 'POST':
    
                $fields = $this->model_t_kur_skbm_ip->fields();
                /* we set the rules */
                /* don't forget to edit these */
				$this->form_validation->set_rules( 'KD_KURIKULUM', lang('KD_KURIKULUM'), 'required|max_length[2]' );
				$this->form_validation->set_rules( 'KD_TINGKAT_KELAS', lang('KD_TINGKAT_KELAS'), 'required|max_length[2]' );
				$this->form_validation->set_rules( 'KD_PROGRAM_PENGAJARAN', lang('KD_PROGRAM_PENGAJARAN'), 'required|max_length[1]' );
				$this->form_validation->set_rules( 'KD_PERIODE_BELAJAR', lang('KD_PERIODE_BELAJAR'), 'required|max_length[1]' );
				$this->form_validation->set_rules( 'KD_MATA_PELAJARAN_DIAJARKAN', lang('KD_MATA_PELAJARAN_DIAJARKAN'), 'required|max_length[5]' );
				$this->form_validation->set_rules( 'ID_STANDAR', lang('ID_STANDAR'), 'required|max_length[3]|integer' );
				$this->form_validation->set_rules( 'ID_KD', lang('ID_KD'), 'required|max_length[3]|integer' );
				$this->form_validation->set_rules( 'ID_IP', lang('ID_IP'), 'required|max_length[3]|integer' );
				$this->form_validation->set_rules( 'SKBM_IP', lang('SKBM_IP'), 'required|max_length[5]|numeric' );
				$this->form_validation->set_rules( 'USERNAME', lang('USERNAME'), 'required|max_length[20]' );
				$this->form_validation->set_rules( 'TANGGAL_AKSES', lang('TANGGAL_AKSES'), 'required' );

				$data_post['KD_KURIKULUM'] = $this->input->post( 'KD_KURIKULUM' );
				$data_post['KD_TINGKAT_KELAS'] = $this->input->post( 'KD_TINGKAT_KELAS' );
				$data_post['KD_PROGRAM_PENGAJARAN'] = $this->input->post( 'KD_PROGRAM_PENGAJARAN' );
				$data_post['KD_PERIODE_BELAJAR'] = $this->input->post( 'KD_PERIODE_BELAJAR' );
				$data_post['KD_MATA_PELAJARAN_DIAJARKAN'] = $this->input->post( 'KD_MATA_PELAJARAN_DIAJARKAN' );
				$data_post['ID_STANDAR'] = $this->input->post( 'ID_STANDAR' );
				$data_post['ID_KD'] = $this->input->post( 'ID_KD' );
				$data_post['ID_IP'] = $this->input->post( 'ID_IP' );
				$data_post['SKBM_IP'] = $this->input->post( 'SKBM_IP' );
				$data_post['USERNAME'] = $this->input->post( 'USERNAME' );
				$data_post['TANGGAL_AKSES'] = $this->input->post( 'TANGGAL_AKSES' );

                if ( $this->form_validation->run() == FALSE )
                {
                    $errors = validation_errors();
                    
                    
                    
                    
              		$this->template->assign( 'action_mode', 'edit' );
              		$this->template->assign( 'errors', $errors );
            		$this->template->assign( 't_kur_skbm_ip_data', $data_post );
            		$this->template->assign( 't_kur_skbm_ip_fields', $fields );
                    $this->template->assign( 'metadata', $this->model_t_kur_skbm_ip->metadata() );
            		$this->template->assign( 'table_name', 'T_kur_skbm_ip' );
            		$this->template->assign( 'template', 'form_t_kur_skbm_ip' );
        		    $this->template->assign( 'record_id', $id );
            		$this->template->display( 'frame_admin.tpl' );
                }
                elseif ( $this->form_validation->run() == TRUE )
                {
				    $this->model_t_kur_skbm_ip->update( $id, $data_post );
				    
					redirect( 't_kur_skbm_ip/show/' . $id );   
                }
            break;
        }
    }



    /**
     *  DELETE RECORD(S)
     *  The 'delete' method of the model accepts int and array  
     */
    function delete( $id = FALSE )
    {
        switch ( $_SERVER ['REQUEST_METHOD'] )
        {
            case 'GET':
                $this->model_t_kur_skbm_ip->delete( $id );
                redirect( $_SERVER['HTTP_REFERER'] );
            break;

            case 'POST':
                $this->model_t_kur_skbm_ip->delete( $this->input->post('delete_ids') );
                redirect( $_SERVER['HTTP_REFERER'] );
            break;
        }
    }
}
